﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;

namespace Hal.Zip.WPF.UserControls
{
	/// <summary>
	/// Interaction logic for FolderPicker.xaml
	/// </summary>
	public partial class FilePicker : System.Windows.Controls.UserControl
	{
		public FilePicker()
		{
			InitializeComponent();
		}

		public static DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(FilePicker), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
		public static DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(string), typeof(FilePicker), new PropertyMetadata(null));

		public string Text { get { return GetValue(TextProperty) as string; } set { SetValue(TextProperty, value); } }
		public string Description { get { return GetValue(DescriptionProperty) as string; } set { SetValue(DescriptionProperty, value); } }

		private void btnBrowse_Click(object sender, RoutedEventArgs e)
		{
			BrowseForFile();
		}
		private void BrowseForFile()
		{
			using (SaveFileDialog dlg = new SaveFileDialog())
			{
				dlg.Filter = "Zip Files (*.zip)|*.zip";
				DialogResult result = dlg.ShowDialog();
				if (result == System.Windows.Forms.DialogResult.OK)
				{
					Text = dlg.FileName;
					BindingExpression be = GetBindingExpression(TextProperty);
					if (be != null)
						be.UpdateSource();
				}
			}
		}

		
	}
}